package com.qdxwx.web.controller.ajax;

import com.qdxwx.common.json.AjaxResult;
import com.qdxwx.common.page.PageRequest;
import com.qdxwx.common.utils.TKConvert;
import com.qdxwx.data.service.teacher.TeacherService;
import com.qdxwx.models.teacher.Teacher;
import com.qdxwx.models.teacher.TeacherQuery;
import com.qdxwx.web.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import jakarta.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * Teacher接口
 * @author developer
 */
@Controller
@RequestMapping("/ajax/teacher")
public class AjaxTeacherController extends BaseController {

	@Autowired
	private TeacherService teacherService;

	/**
	 * 教师列表展示
	 */
	@RequestMapping("/list.json")
	@ResponseBody
	public AjaxResult teacherList(HttpServletRequest request) {
		int currentPage = TKConvert.toInteger(request.getParameter("page"));
		int subjectId = TKConvert.toInteger(request.getParameter("subjectId"));
		int starId = TKConvert.toInteger(request.getParameter("starId"));
		int isElite = TKConvert.toInteger(request.getParameter("isElite"));
		int isHot = TKConvert.toInteger(request.getParameter("isHot"));
		int orderBy = TKConvert.toInteger(request.getParameter("orderBy"));
		int pageSize = TKConvert.toInteger(request.getParameter("limit"), 10);
		//String searchKey = TKString.searchKeyFilter(request.getParameter("searchKey"));
		TeacherQuery query = new TeacherQuery();
		//query.setName(searchKey);
		query.setSubjectId(subjectId);
		query.setStarId(starId);
		query.setIsElite(isElite);
		query.setIsHot(isHot);
		query.setOrderBy(orderBy);
		query.setIsDisabled(0);
		PageRequest page = new PageRequest();
		page.setCurrentPage(currentPage);
		page.setPageSize(pageSize);
		// 查询老师
		List<Teacher> teacherList = teacherService.getList(query, page);
		return AjaxResult.success(teacherList);
	}
}